/*
 * function:分页类，在进行分页查询的时候，保存分页信息的一个类。
 * author：john
 * date：2013-09-06
 */
package com.hosever.utils;

public class Page {
	private long totalSize = 0; //总条数
	private long pageSize = 10; //每页显示的数量
	private long totalPage = 0; //总页数
	private long currentPage = 1; //当前页
	private long start = 0;  //开始查询的数。
	private long end = 0;  //结束查询的数。
	
	public Page(){
		super();
	}

	public Page(long totalSize, long pageSize, long totalPage,
			long currentPage, long start, long end) {
		super();
		this.totalSize = totalSize;
		this.pageSize = pageSize;
		this.totalPage = totalPage;
		this.currentPage = currentPage;
		this.start = start;
		this.end = end;
	}
	
	//获取总条数
	public long getTotalSize() {
		return totalSize;
	}
	
	//设置总条数
	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
		//计算总页数。
		this.totalPage = (this.totalSize + (this.pageSize -1))/this.pageSize;
		//重新计算当前面和start
		this.setCurrentPage(this.currentPage);
	}
	
	//获取每页显示条数
	public long getPageSize() {
		return pageSize;
	}
	
	//设置每页显示条数
	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
		//修改每页数量，重新计算总页数。
		this.totalPage = (this.totalSize + (this.pageSize -1))/this.pageSize;
	}
	
	//获取总页数
	public long getTotalPage() {
		return totalPage;
	}
	
	//获取当前页
	public long getCurrentPage() {
		return currentPage;
	}
	
	//设计当前页时，计算stare
	public void setCurrentPage(long currentPage) {
		//设置当前页时，判断两端。
		if(currentPage < 1){
			currentPage = 1L;
		}
		if(currentPage > this.totalPage && totalPage != 0){
			currentPage = this.totalPage;
		}
		this.currentPage = currentPage;
		//计算起始
		this.start = (this.currentPage - 1)*this.pageSize;
	}
	
	//从第start开始查询
	public long getStart() {
		return start;
	}
	
	//设置从第start开始查询
	public void setStart(long start) {
		this.start = start;
	}
	
	//获取查询到第end条
	public long getEnd() {
		return end;
	}
	
	//设置查询到第end条
	public void setEnd(long end) {
		this.end = end;
	}
	
}
